package com.throwsDemo;

import java.util.Scanner;

/**
 * @Author "milian"
 * @Date 2021/7/18 0018 19:13
 */
public class test {
    public static void main(String[] args) {
        student student = new student();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入姓名：");
        String name = sc.nextLine();
        student.setName(name);
        while (true){
            System.out.println("请输入年龄：");
            String ageStr = sc.nextLine();
            try {
                int age = Integer.parseInt(ageStr);
                student.setAge(age);
                break;
            }catch (NumberFormatException e){
                System.out.println("请输入一个整数");
                continue;
            }catch (AgeOutOfBoundsException e){
                System.out.println(e.toString());
                System.out.println("请输入一个符合范围的年龄");
                continue;
            }
        }
        System.out.println(student);
    }
}
